#pragma once

#include <afxmt.h>

class CMyThread
{
public:
	class IWorker
	{
	public:
		virtual bool Work() = 0;
		virtual bool IsEnding() = 0;
		virtual void Terminated() = 0;
	};

	CMyThread(void);
	virtual ~CMyThread(void);

	bool StartWith(IWorker& rWorker);
	void Terminate(void);

private:
	typedef struct
	{
		CMyThread* m_pThis;
		IWorker& m_rWorker;
	} MyThreadParam_t;

	static DWORD WINAPI ThreadStartRoutine(LPVOID lpThreadParameter);
	void MyThreadProc(IWorker& rWorker);
private:
	volatile HANDLE m_hThread;
	volatile HANDLE m_hQuit;
	CCriticalSection m_cs;
};
